#include <s32strm.h>
#include <e32cmn.h>
#include <QikApplication.h>
#include <QikCategoryModel.h>

#include "PinQDocument.h"
#include "PinQAppUi.h"
#include "PinQModel.h"
#include "PinQExternalInterface.h"

CPinQDocument* CPinQDocument::NewL(CQikApplication& aApp)
	{
	CPinQDocument* self = new (ELeave) CPinQDocument(aApp);
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop(self);
	return self;
	}

CPinQDocument::CPinQDocument(CQikApplication& aApp): CQikDocument(aApp)
	{
	}

CPinQDocument::~CPinQDocument()
	{
	delete iPinQModel;
	}

void CPinQDocument::ConstructL()
	{
		iPinQModel	= CPinQModel::NewL();
	}

CEikAppUi* CPinQDocument::CreateAppUiL()
	{
	return new (ELeave) CPinQAppUi();
	}

void CPinQDocument::StoreL(CStreamStore& aStore, CStreamDictionary& aStreamDic) const
	{
	RStoreWriteStream stream;
	TStreamId streamId = stream.CreateLC(aStore);
	aStreamDic.AssignL(KUidPinQStore, streamId);
	stream << iPreferences;
	iPinQModel->StoreL(stream);
	stream.CommitL();
	CleanupStack::PopAndDestroy(); // stream
	}

void CPinQDocument::RestoreL(const CStreamStore& aStore, const CStreamDictionary& aStreamDic)
	{
	TStreamId streamId(aStreamDic.At(KUidPinQStore));
	RStoreReadStream stream;
	stream.OpenLC(aStore, streamId);
	if(streamId != KNullStreamId)
		{
		stream >> iPreferences;
 		iPinQModel->RestoreL(stream);
		}

	CleanupStack::PopAndDestroy(); 
	}
	
// vim: ts=2:sw=2
